package com.yopinclub.resloader;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;


public class ImageDownloadTask extends LeeAsyncTask<String, Void, Bitmap> {

	@Override
	protected Bitmap doInBackground(String... urls) {
		Bitmap bitmap = null;
		InputStream is = null;
		HttpURLConnection conn = null;
		try {
			String mUrl = urls[0];
			URL url = new URL(mUrl);
			conn = (HttpURLConnection) url.openConnection();
			conn.setConnectTimeout(20000);
			conn.connect();
			if (conn != null && conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
				is = conn.getInputStream();
				bitmap = BitmapFactory.decodeStream(is);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return bitmap;
	}
	
	@Override
	protected void onPostExecute(Bitmap result) {
		imageDownloadComplete(result);
	}
	
	public void imageDownloadComplete(Bitmap bitmap){
		
	}
}
